package io.renren.controller;

import io.renren.annotation.LoginUser;
import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.utils.Result;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.DefaultGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.dto.SmallCanteenPurchasemxDTO;
import io.renren.dto.TemporaryOrderDTO;
import io.renren.dto.TemporaryOrdermxDTO;
import io.renren.entity.UserEntity;
import io.renren.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.Map;

/**
 * 临时采购明细表 
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-12-31
 */
@RestController
@RequestMapping("api/temporaryordermx")
@Api(tags="临时采购表")
public class TemporaryOrdermxController {
    @Autowired
    private TemporaryOrdermxService temporaryOrdermxService;

    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
    })
    public Result<PageData<TemporaryOrdermxDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<TemporaryOrdermxDTO> page = temporaryOrdermxService.page(params);

        return new Result<PageData<TemporaryOrdermxDTO>>().ok(page);
    }

    /**
     * 根据主厨id 和类型查询表中是否有数据 油就返回
     */
    @PostMapping("getTemOrdermx")
    @ApiOperation("查询临时表订单")
    public Result<Map> getTemOrdermx(@RequestBody TemporaryOrdermxDTO dto, @LoginUser UserEntity entity){
        System.out.println(dto);
        Map temOrdermx = temporaryOrdermxService.getTemOrdermx(dto, entity);
        return new Result<Map>().ok(temOrdermx);
    }
    @PostMapping("saveFood")
    @ApiOperation("保存商品")
    public void saveFood(@RequestBody TemporaryOrdermxDTO dto,@LoginUser UserEntity entity){//
        temporaryOrdermxService.saveFood(dto,entity);
        return ;
    }
    @PostMapping("updateFood")
    @ApiOperation("修改商品")
    public Result updateFood(@RequestBody TemporaryOrdermxDTO dto,@LoginUser UserEntity entity){
        temporaryOrdermxService.updateFood(dto,entity);

        return new Result();
    }
    @PostMapping("deleteFood")
    @ApiOperation("删除商品")
    public Result deleteFood(@RequestBody TemporaryOrdermxDTO dto,@LoginUser UserEntity entity){
        temporaryOrdermxService.deleteFood(dto,entity);
        return new Result();
    }
}